<template>
  <div class="builder-container">
    <div class="comp-select" :class="compExpand ? 'expand' : 'collapse'">
      <ElScrollbar>
        <div class="content">
          <CompSelect />
        </div>
      </ElScrollbar>
      <div class="expand-btn">
        <ElIcon @click="compExpand = !compExpand">
          <ArrowLeftBold v-if="compExpand" />
          <ArrowRightBold v-else />
        </ElIcon>
      </div>
    </div>
    <div class="main">
      <ElScrollbar>
        <CompRender />
      </ElScrollbar>
    </div>
    <div class="comp-setting" :class="compSetting ? 'expand' : 'collapse'">
      <ElScrollbar>
        <div class="content">
          <div class="comp_render_tools">
            <ElFormItem label="隐藏按钮">
              <ElSwitch v-model="hideBtn" />
            </ElFormItem>
            <ElFormItem label="隐藏边框">
              <ElSwitch v-model="hideBorder" />
            </ElFormItem>
          </div>
          <CompConfig :editors="editors" :compId="compId" />
        </div>
      </ElScrollbar>
      <div class="expand-btn">
        <ElIcon @click="compSetting = !compSetting">
          <ArrowRightBold v-if="compSetting" />
          <ArrowLeftBold v-else />
        </ElIcon>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref, provide } from "vue";
import CompConfig from "./CompConfig/index.vue";
import CompSelect from "./CompSelect/index.vue";
import CompRender from "./CompRender/index.vue";
import { useCodeBuilderState } from "@/store/codeBuilder/codeBuilder";
const compExpand = ref(true);
const compSetting = ref(true);
const codeBuilderState = useCodeBuilderState();
const editors = computed(() => codeBuilderState?.currentComp?.editors);
const compId = computed(() => codeBuilderState?.currentComp?.id);
const hideBtn = ref(false);
const hideBorder = ref(false);
// const builderContainer = useTemplateRef("builderContainer");

// 更新组件配置
function updateComponentConfig(editorKey, payload) {
  codeBuilderState.dispatchUpdateComponentConfig(editorKey, payload);
}

provide("updateComponentConfig", updateComponentConfig);
provide("hideBtn", hideBtn);
provide("hideBorder", hideBorder);
</script>

<style scoped>
.builder-container {
  position: relative;
  display: flex;
  width: 100%;
}
.main {
  flex: 1;
  border: 1px solid var(--border-color);
  margin: 0 15px;
  min-width: 0;
}
.comp-select,
.comp-setting {
  position: relative;
  height: 100%;
  width: 0;
  transition: width 0.3s ease;
  flex: 0 0 auto;
  width: 350px;
}
.main,
.comp-select,
.comp-setting {
  height: calc(100vh - 125px);
  background: var(--bg-primary);
  border-radius: 5px;
}

.comp-select.collapse .content,
.comp-setting.collapse .content {
  overflow: hidden;
}

.comp-select.collapse,
.comp-setting.collapse {
  width: 0;
}
.expand-btn {
  position: absolute;
  top: 10px;
  width: 20px;
  height: 25px;
  line-height: 21px;
  background: inherit;
  box-shadow: inherit;
}
.comp-select .expand-btn {
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
  text-align: right;
  padding-right: 10px;
  right: -20px;
}
.comp-setting .expand-btn {
  left: -20px;
  text-align: right;
  text-align: left;
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
}
.comp_render_tools {
  display: flex;
  margin: 10px 10px 0 10px;
  gap: 10px;
}
.comp_render_tools .el-form-item {
  margin-bottom: 0;
}
</style>
